﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace sy3_3
{
    class Rect
    {
        protected double length;
        protected double width;

        public Rect()
        {
            length = 0;
            width = 0;
        }

        public Rect(double l, double w)
        {
            length = l;
            width = w;
        }

        public virtual double GetArea()
        {
            return length * width;
        }

        public double GetPerimeter()
        {
            return 2 * (length + width);
        }
    }

    class Cubold : Rect
    {
        private double height;

        public Cubold(double l, double w, double h) : base(l, w)
        {
            height = h;
        }

        public override double GetArea()
        {
            return 2 * (length * width + length * height + width * height);
        }

        public double GetVolume()
        {
            return length * width * height;
        }
    }
    internal class Program
    {

        static void Main(string[] args)
        {
            double l, w, h;

            Console.Write("请输入矩形长：");
            l = Convert.ToDouble(Console.ReadLine());
            Console.Write("请输入矩形宽：");
            w = Convert.ToDouble(Console.ReadLine());

            Rect rect = new Rect(l, w);
            Console.WriteLine($"解：矩形面积为 {rect.GetArea()} ，周长为 {rect.GetPerimeter()} 。");

            Console.WriteLine("\n====在此基础上构造矩体====");
            Console.Write("请输入矩体高：");
            h = Convert.ToDouble(Console.ReadLine());

            Cubold cub = new Cubold(l, w, h);
            Console.WriteLine($"解：矩体表面积为 {cub.GetArea()} ，体积为 {cub.GetVolume()} 。");

            Console.WriteLine("\n按任意键结束程序：");
            Console.ReadKey();
        }
    }
}
